from flask_sqlalchemy import SQLAlchemy
from flask import Flask
import os
from datetime import timedelta


# 创建 Flask 应用
app = Flask(__name__)

# 配置当前服务的数据库参数    用于连接的数据库 URI      //root:密码@ip:port/数据库名
# app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://bridge:bridge*123@127.0.0.1:3306/drinktalk"
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:123@127.0.0.1:3306/drinktalk"
# 使用一组随机数对session进行加密
app.config['SECRET_KEY'] = os.urandom(24)                      
# 修改session 过期时间 --> session.permanent = True 
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=5)   
# 消除SQLALCHEMY_TRACK_MODIFICATIONS警告
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
# # SameSite = None
# app.config['SESSION_COOKIE_SAMESITE'] = "None"
# # secure = true 使 SameSite = None 生效
# app.config['SESSION_COOKIE_SECURE'] = True

# 创建 SQLAlchemy 对象，并把 Flask 应用传递给它作为参数
db =  SQLAlchemy(app)


